<template>
  <div>
    <!-- 面包屑导航条 -->

    <!--卡片视图-->
    <el-card class="box-card" body-style="width:1500px">


      <el-form :model="searchForm" label-width="70px">
        <el-col :span="5">
          <el-form-item label="关键字">
            <el-input v-model="searchForm.aname"  size="small"></el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <el-button type="info" plain @click="searchList">搜索</el-button>

      <el-button type="primary" plain @click="tigFormVisible = true">添加合同</el-button>

      <h2>总金额:{{summoneys}}</h2>
      <el-table
        :data="tigeList"
        stripe
        style="width: 100%">
        <el-table-column
          prop="id"
          label="编号"
          width="180">
        </el-table-column>
        <el-table-column
          prop="tname"
          label="合同名称"
          width="180">
        </el-table-column>

        <el-table-column
          prop="aname"
          label="甲方"
          width="180">
        </el-table-column>
        <el-table-column
          prop="bname"
          label="乙方">
        </el-table-column>

        <el-table-column
          label="合同金额"
          prop="money" width="160">
        </el-table-column>

        <el-table-column
          label="状态">
          <template slot-scope="scope">
            {{scope.row.status | staFit}}
          </template>
        </el-table-column>
        <el-table-column
          label="签订日期">
          <template slot-scope="scope">
            {{scope.row.tigtime | dateFit("YYYY/MM/DD")}}
          </template>
        </el-table-column>
        <el-table-column
          fixed="right"
          label="操作">
          <template slot-scope="scope">
            <el-button @click="subResume(scope.row.id)" size="small" type="text" v-if="scope.row.status==0 ">提交
            </el-button>
            <el-button @click="passTig(scope.row.id)" size="small" type="text"  v-if="role==1 && scope.row.status==1">通过
            </el-button>
            <el-button @click="NopassTig(scope.row.id)" size="small" type="text"  v-if="role==1 && scope.row.status==1">不通过
            </el-button>
            <el-button @click="getTig(scope.row.id)" size="small" type="text">查看
            </el-button>
          </template>
        </el-table-column>
      </el-table>

      <el-dialog :close-on-click-modal="false" :title="tigForm.id==null?'添加简历':'简历审核'" :visible.sync="tigFormVisible"
                 @closed="clearUserForm" width="850px"> <!--用户表单框 -->

        <el-form ref="form" :model="tigForm" label-width="80px">
          <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="合同编号">
                <el-input v-model="tigForm.id"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="合同名称">
                <el-input v-model="tigForm.tname"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="甲方公司">
                <el-input v-model="tigForm.aname"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="甲方电话">
                <el-input v-model="tigForm.atel"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="乙方公司">
                <el-input v-model="tigForm.bname"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="乙方电话">
                <el-input v-model="tigForm.btel"></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="20">
            <el-col :span="10">
              <el-form-item label="合同总金额">
                <el-input v-model="tigForm.money" :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="10">
              <el-form-item label="签订时间">
                <el-date-picker
                  v-model="tigForm.tigtime"
                  type="date"
                  placeholder="选择日期">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-button
            style="float: left;"
            size="mini"
            type="danger"
            @click="addRow()">新增明细</el-button>

          <el-table
            :data="goodss"
            style="width: 100%">
            <el-table-column
              label="商品名称"
              width="180">
              <template slot-scope="scope">
                <el-input v-model="scope.row.gname"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              label="单价"
              width="180">
              <template slot-scope="scope">
                <el-input v-model="scope.row.price"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              label="采购数量"
              width="180">
              <template slot-scope="scope">
                <el-input v-model="scope.row.nums" @blur="summoney()"></el-input>
              </template>
            </el-table-column>
            <el-table-column
              label="总价"
              width="180">
              <template slot-scope="scope">
                <el-input :disabled="true" v-model="scope.row.sumprice=scope.row.price*scope.row.nums" ></el-input>
              </template>
            </el-table-column>
            <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button
                  size="mini"
                  type="danger"
                  @click="delRow(scope.$index, scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-form>

        <el-button style="float: right; padding: 3px 0" type="text" @click="saveCv()">保存</el-button>
      </el-dialog>

    </el-card>

  </div>
</template>

<script>
    export default {
        name: "TigList",
      data(){
          return {
            searchForm: {},
            tigeList: [],
            tigFormVisible:false,
            tigForm:{id:null,},
              goodss:[],
            summoneys:null,
            role:null,
          }
      },
      mounted() {
          this.searchList();
          this.tigForm.id=Math.floor(Math.random()*10000000);
          this.role=sessionStorage.getItem("role");
          this.getMoney();
      },
      methods:{
          getMoney:function(){
            this.$http.get("/tigether/getMoney").then((res)=>{

              this.summoneys=res.data.result.summoneys;
            })
          },
        NopassTig:function(ids){
          this.$http.post("/tigether/NopassTig/"+ids).then((res)=>{
            if(res.data.success){
              alert("操作成功");
            }else{
              alert("操作失败");
            }
          })
          location.reload();
        },
        passTig:function(ids){
          this.$http.post("/tigether/passTig/"+ids).then((res)=>{
            if(res.data.success){
              alert("操作成功");
            }else{
              alert("操作失败");
            }
          })
          location.reload();
        },
        subResume:function(ids){
          this.$http.post("/tigether/subResume/"+ids).then((res)=>{
            if(res.data.success){
              alert("提交成功");
            }else{
              alert("提交失败");
            }
          })
          location.reload();
        },
        searchList:function () {
          var uid=JSON.parse(sessionStorage.getItem("user")).id;
          this.$http.post("/tigether/list/"+uid,this.searchForm).then((res)=>{
              this.tigeList=res.data.result;
          })
        },
        addRow:function () {
          this.goodss.push({});
        },
        delRow:function (index) {
          this.goodss.splice(index,1)
        },
        saveCv:function () {

          this.tigForm.uid=JSON.parse(sessionStorage.getItem("user")).id;
          this.$http.post("/tigether/saveCv",{tigForms:this.tigForm,goodss:this.goodss}).then((res)=>{
            if(res.data.success){
              alert("保存成功");
              this.tigFormVisible=false;
              location.reload();

            }else{
              alert("保存失败");
            }
          })
        },
        summoney:function () {
          var total=0;
          for(var i=0;i<this.goodss.length;i++){
            total=total+Number(this.goodss[i].sumprice);
          }
          this.tigForm.money=total;
        },
        getTig:function (tid) {
          this.tigFormVisible=true;
            this.$http.post("/tigether/getTig/"+tid).then((res)=>{
              debugger;
              this.tigForm=res.data.tigForms;
              this.goodss=res.data.goodss;
            })
        }
      },
      filters:{
        staFit:function (val) {
          if(val==0){
            return "未提交"
          }
          if(val==1){
            return "待审核"
          }
          if(val==2){
            return "通过"
          }
          if(val==3){
            return "未通过"
          }
        }
      }
    }
</script>

<style scoped>

</style>
